package com.pbc.gmp.action;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.pbc.gmp.commons.base.BaseController;
import com.pbc.gmp.commons.utils.BeanUtils;
import com.pbc.gmp.commons.utils.PageInfo;
import com.pbc.gmp.model.EquipmentTypeInfo;
import com.pbc.gmp.model.basemodel.Equipmentdetail;
import com.pbc.gmp.model.basemodel.Equipmenttype;
import com.pbc.gmp.model.selectModelVo.EquipmentTypeWhere;
import com.pbc.gmp.model.selectModelVo.EquipmentdetailWhere;
import com.pbc.gmp.service.IEquipmentdetailService;
import com.pbc.gmp.service.IEquipmenttypeService;
import com.pbc.gmp.service.impl.EquipmentdetailServiceImpl;
import com.xiaoleilu.hutool.convert.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author kjk
 * @since 2018-06-14
 */
@Controller
@RequestMapping("/equipmenttype")
public class EquipmenttypeController extends BaseController {
    @Autowired
    private IEquipmenttypeService equipmenttypeService;
    @RequestMapping(value="/eqtype")
    @ResponseBody
    public List<Equipmenttype> eqtype() {
            List<Equipmenttype> list =equipmenttypeService.selectList(null);
        return list;
    }
    @RequestMapping(value="/manager")
    public String manager() {
        return "service/equipment/equipmentTypeManger";
    }

    @RequestMapping(value="/addPage")
    public String addPage() {
        return "service/equipment/equipmentTypeAdd";
    }
    @RequestMapping(value="/editPage")
    public String editPage(Model model, @RequestParam Long id) {

            Equipmenttype equipmenttype    = equipmenttypeService.selectById(id);
            model.addAttribute("equtype",equipmenttype );


        return "service/equipment/equipmentTypeEdit";

    }

    @RequestMapping(value="/equTypeList")
    @ResponseBody
    public Object equimentList(EquipmentTypeWhere equTypeWhere, Integer page, Integer rows, String sort, String order) {
        PageInfo pageInfo = new PageInfo(page, rows, sort, order);
        Map<String, Object> condition = new HashMap<String, Object>();

        if (equTypeWhere.getIscheck()!=null) {
            condition.put("ischeck", equTypeWhere.getIscheck());
        }
        if (equTypeWhere.getChekrate()!=null) {
            condition.put("chekrate", equTypeWhere.getChekrate());
        }


        pageInfo.setCondition(condition);
        equipmenttypeService.selectEquipmentTypeByDetailWhere(pageInfo);
        return pageInfo;
    }
    /**
     *
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object add(Equipmenttype equ) {
        equipmenttypeService.insertOrUpdate(equ);
        return renderSuccess("更新成功");
    }
    @RequestMapping(value = "/delete", method = {RequestMethod.POST })
    @ResponseBody
    public Object delete(String ids) {
        List<Long > idlist= Arrays.asList(ids.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());

        equipmenttypeService.deleteBatchIds(idlist);
        return renderSuccess("删除成功！");
    }
}
